package com.itheima.stargraph.utils;

import com.itheima.stargraph.pojo.User;

/**
 *
 *
 * @Author mr.zhang
 * Date 2025/6/9 15:15
 */
public class UserThreadLocalUtils {

    private static ThreadLocal<User> userThreadLocal = new ThreadLocal<>();

    /**
     * 设置用户到本地线程中
     * @param user
     */
    public static void setUser(User user){
        userThreadLocal.set(user);
    }

    /**
     * 从本地线程中获取用户
     * @return
     */
    public static User getUser(){
        User user = userThreadLocal.get();
        return user;
    }

    /**
     * 清除资源
     */
    public static void remove(){
        userThreadLocal.remove();
    }
}
